package cn.com.open.itembank.controller;

import cn.com.open.itembank.common.GlobalConst;
import cn.com.open.itembank.entity.CourseItemBank;
import cn.com.open.itembank.dto.ItemBankCount;
import cn.com.open.itembank.interceptor.Log;
import cn.com.open.itembank.service.AppRemoteService;
import cn.com.open.itembank.utils.ListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author lucky
 */

/**
 * 应用控制器
 */
@RestController
@RequestMapping("/app")
public class AppController extends BaseController {
    @Autowired
    private AppRemoteService service;

    //region 新增相关（Create：理论方法 HttpPost）

    //endregion

    //region 删除相关（Delete：理论方法 HttpDelete）

    //endregion

    //region 更新相关（Update：理论方法 HttpPut）

    //endregion

    //region 查询相关（Retrieve：理论方法 HttpGet）

    //region 获取应用列表

    /**
     * 获取应用列表
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    @Log(optType = "获取应用列表", optDescription = "获取应用列表", keyName = "")
    @RequestMapping(method = RequestMethod.GET)
    public void getAppList(HttpServletRequest request, HttpServletResponse response) {
        List<String> result = service.getAppList();
        responseList(request, response, result);
    }

    //endregion

    //#region 根据AppId和OrgId获取题库信息

    /**
     * 根据应用ID和机构ID获取题库信息
     *
     * @param request  请求对象
     * @param response 响应对象
     * @param appKey   应用ID
     * @param orgId    机构ID
     */
    @Log(optType = "根据应用ID和机构ID获取题库信息", optDescription = "根据应用ID和机构ID获取题库信息，应用ID：%s", keyName = "appId")
    @RequestMapping(value = "/{appKey}/org/{orgId}/itembanks", method = RequestMethod.GET)
    public void getItembankListByAppIdAndOrgId(HttpServletRequest request, HttpServletResponse response,
                                               @PathVariable(value = "appKey") String appKey,
                                               @PathVariable(value = "orgId") String orgId) {

        List<CourseItemBank> result = service.getItembankListByAppKeyAndOrgId(appKey, orgId);
        responseList(request, response, result);
    }

    //endregion

    //region 根据appKey获取对应题库题量列表

    /**
     * 根据appKey获取对应题库题量列表
     *
     * @param request  请求对象
     * @param response 响应对象
     * @param appKey   应用ID
     */
    @Log(optType = "根据应用ID获取题库试题数量", optDescription = "根据应用ID获取题库试题数量，应用ID：%s", keyName = "appId")
    @RequestMapping(value = "/{appKey}/itembank/questioncount", method = RequestMethod.GET)
    public void getItembankQuestionCountByAppKey(HttpServletRequest request, HttpServletResponse response,
                                                 @PathVariable(value = "appKey") String appKey) {

        List<ItemBankCount> result = service.getItembankQuestionCountByAppKey(appKey);
        responseList(request, response, result);
    }

    //endregion

    //endregion
}
